package com.service;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.List;

import com.dao.TreatmentTransactionDAO;
import com.domain.TreatmentTransaction;

public class TransactionService {
	public void addSales(String employeeId, String productId,
			int productVersion) {
		TreatmentTransactionDAO dao = new TreatmentTransactionDAO();
		TreatmentTransaction t = new TreatmentTransaction();
		t.setEmployeeId(employeeId);
		t.setTreatmentCode(productId);
		t.setTreatmentVersion(productVersion);
		t.setTransactionDate(new Date(new java.util.Date().getTime()));
		t.setAction("Sales");
		t.setSpecialOffer(false);
		dao.insertTransaction(t);
	}
	public void refundSales(int transactionId, float price) {
		TreatmentTransactionDAO dao = new TreatmentTransactionDAO();
		TreatmentTransaction t = dao.getTreatmentTransactionById(transactionId, "sales");
		TreatmentTransaction newTransaction = new TreatmentTransaction();
		newTransaction.setEmployeeId(t.getEmployeeId());
		newTransaction.setTreatmentCode(t.getTreatmentCode());
		newTransaction.setTreatmentVersion(t.getTreatmentVersion());
		newTransaction.setTransactionDate(t.getTransactionDate());
		newTransaction.setAction("Refund");
		newTransaction.setPrice(price);
		newTransaction.setSpecialOffer(true);
		newTransaction.setTransactionId(t.getTransactionId());
		dao.insertTransaction(newTransaction);
	}
	public TreatmentTransaction searchTransactionById(int transactionId) {
		TreatmentTransactionDAO dao = new TreatmentTransactionDAO();
		return dao.getTreatmentTransactionById(transactionId, "sales");
	}
	public List<TreatmentTransaction> searchTransactionByQuery(String sql) {
		TreatmentTransactionDAO dao = new TreatmentTransactionDAO();
		return dao.searchBySQL(sql);
	}
}
